﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;

public static class PopupPanelManager
{
	public static Dictionary<string, BasePopupPanel> popupPanels = new Dictionary<string, BasePopupPanel>();

	public static T Get<T>() where T : BasePopupPanel
	{
		string name = typeof(T).ToString();
		BasePopupPanel panel;
		if (!popupPanels.TryGetValue(name, out panel))
		{
			panel = (T)Activator.CreateInstance(typeof(T));
			panel.Init();
			popupPanels.Add(name, panel);
		}
		return (T)panel;
	}

	public static T Open<T>(params object[] para) where T : BasePopupPanel
	{
		BasePopupPanel panel = Get<T>();
		panel.Show(para);
		return (T)panel;
	}

	public static void Dispose(string name)
	{
		if (!popupPanels.ContainsKey(name))
		{
			return;
		}
		BasePopupPanel panel = popupPanels[name];
		popupPanels.Remove(name);
		panel.Dispose();
	}
}
